home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / close.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-10  |  3.2 KB  |  120 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     close.c
  4.  
  5.     This module handles window closing.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include "glob.h"
  13. #include "activate.h"
  14. #include "child.h"
  15. #include "close.h"
  16. #include "mark.h"
  17. #include "newsrc.h"
  18. #include "send.h"
  19. #include "util.h"
  20. #include "wind.h"
  21.  
  22.  
  23. /*    DoCloseWindow removes a window from the screen and disposes of all the window's
  24.     associated data structures. 
  25. */
  26.  
  27. Boolean DoCloseWindow (WindowPtr wind)
  28. {
  29.     TWindow **info;
  30.     TGroup **groupArray,theGroup;
  31.     TUnread **pUnreadRec,**qUnreadRec;
  32.     EWindowKind kind;
  33.     short i,numGroups;
  34.     Point offPt;
  35.     GrafPtr savePort;
  36.  
  37.     info = (TWindow**)GetWRefCon(wind);
  38.     kind = (**info).kind;
  39.     
  40.     /* Save window if necessary. */
  41.     
  42.     if (kind == kUserGroup) {
  43.         if ((**info).changed && (**info).autoFetched && gPrefs.autoFetchnewsrc)
  44.             DoSendGroupListToHost(wind, gAutoFetchHost, gAutoFetchName,
  45.                 gAutoFetchPass, gAutoFetchPath);
  46.         if ((**info).changed && !(CheckForSave(wind))) return false;
  47.     } else if (kind == kPostMessage || kind == kMailMessage) {
  48.         if ((**info).changed && !CheckForSend(wind)) return false;
  49.     }
  50.     
  51.     /* Close all child windows and remove this window from the child
  52.        list of its parent window. */
  53.     
  54.     while ((**info).childList != nil) DoCloseWindow((**(**info).childList).childWindow);
  55.     RemoveChild((**info).parentWindow, wind);
  56.     
  57.     /* Deactivate the window. */
  58.     
  59.     HandleActivate(wind,false);
  60.     
  61.     /* Remember size and position of full group list window. */
  62.     
  63.     if (kind == kFullGroup) {
  64.         gPrefs.groupWindowRect = wind->portRect;
  65.         SetPt(&offPt,0,0);
  66.         GetPort(&savePort);
  67.         SetPort(wind);
  68.         LocalToGlobal(&offPt);
  69.         SetPort(savePort);
  70.         OffsetRect(&gPrefs.groupWindowRect,offPt.h,offPt.v);
  71.     }
  72.     
  73.     /* If closing a subject window, update the unread list for the parent
  74.        group. */
  75.        
  76.     if (kind == kSubject) UpdateUnreadList(wind);
  77.     
  78.     /* Dispose all of the window's associated data structures. */
  79.  
  80.     if (kind == kUserGroup) {
  81.         groupArray = (**info).groupArray;
  82.         numGroups = (**info).numGroups;
  83.         for (i = 0; i < numGroups; i++) {
  84.             theGroup = (*groupArray)[i];
  85.             pUnreadRec = theGroup.unread;
  86.             while (pUnreadRec != nil) {
  87.                 qUnreadRec = (**pUnreadRec).next;
  88.                 MyDisposHandle((Handle)pUnreadRec);
  89.                 pUnreadRec = qUnreadRec;
  90.             }
  91.         }
  92.     }
  93.     
  94.     if ((**info).theList != nil) LDispose((**info).theList);
  95.     if ((**info).theTE != nil) TEDispose((**info).theTE);
  96.     if ((**info).groupArray != nil && kind != kFullGroup)
  97.         MyDisposHandle((Handle)(**info).groupArray);
  98.     MyDisposHandle((Handle)(**info).subjectArray);
  99.     if (kind == kSubject) MyDisposHandle((**info).strings);
  100.     MyDisposHandle((**info).fullText);
  101.     MyDisposHandle((**info).headerText);
  102.     MyDisposHandle((Handle)(**info).sectionBreaks);
  103.     MyDisposHandle((Handle)(**info).msgId);
  104.     MyDisposHandle((**info).unsubscribed);
  105.     if ((**info).collapseTriangle != nil) KillPoly((**info).collapseTriangle);
  106.     if ((**info).expandTriangle != nil) KillPoly((**info).expandTriangle);
  107.     MyDisposHandle((Handle)info);
  108.     
  109.     /* Remove window title from Windows menu. */
  110.  
  111.     RemoveWindMenu(wind);
  112.     
  113.     /* Finally, dispose the window record. */
  114.     
  115.     DisposeWindow(wind);
  116.     
  117.     return true;
  118. }
  119.  
  120.